package com.jack.jetpackapp

import kotlinx.coroutines.Runnable
import org.junit.Test

/**
 * 测试多线程
 *
 * @author Jack 2021-06-17 22:54
 */
class ThreadTest {

    @Test
    fun test() {
        val runnable = MyRunnable()
        Thread(runnable, "1号窗口").start()
        Thread(runnable, "2号窗口").start()
        Thread(runnable, "3号窗口").start()
    }
}

class MyRunnable : Runnable {
    private var ticket = 200

    override fun run() {
        while (ticket > 0) {
            Thread.sleep(20)
            println("${Thread.currentThread().name}正在出售第${ticket --}张票")
        }
    }

}